package com.ymttest.business.service;

import java.io.IOException;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;

import com.ymatou.im.api.parameter.SendMessageBean;
import com.ymatou.im.api.service.SendMessageCall;

public class MessageCallService {
	// {"appId":"app.ymatou.com","fromUserId":1064,"message":"Message0","needAutoReply":false,"toUserId":3383}
	/**
	 * 发送消息 默认 "appId":"app.ymatou.com" "needAutoReply":false
	 * 
	 * @param message
	 *            Map 例如<br>
	 *            "fromUserId":1064 int<br>
	 *            "message":"Message0" String<br>
	 *            "toUserId":3383 int
	 * @return 返回报文 {"Msg":"操作成功","Status":200,"Result":{"MessageId":
	 *         "10337223-f93b-4ac8-826b-e0f8aceb18f9"
	 *         ,"PostTime":"2015-07-21 11:22:08"
	 *         ,"LongPostTime":1437448928000.0,"AutoReplyMessageId"
	 *         :null,"FromUserUnReadMessageCount"
	 *         :0,"ToUserUnReadMessageCount":13}}
	 */
	public static String sendMessage(Map message) {
		SendMessageBean smb = new SendMessageBean();
		SendMessageCall smc = new SendMessageCall();
		int fromUserId = (Integer) message.get("fromUserId");
		int toUserId = (Integer) message.get("toUserId");
		String msg = (String) message.get("message");
		smb.setFromUserId(fromUserId);
		smb.setMessage(msg);
		smb.setToUserId(toUserId);
		smb.setNeedAutoReply(false);
		smb.setAppId("app.ymatou.com");
		smc.setData(false,smb);
		try {
			smc.callService();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return "ok";
	}
}
